package ch06;

public class Student {
    private String id;
    private String name;
    private int age;

    public Student() {
    }

    public Student(String id, String name, int age) throws MyException,Exception {
        setId(id);
        this.name = name;
        setAge(age);
    }

    public String getId() {
        return id;
    }

    // id 以 880开头的 8位数据
    public void setId(String id) throws Exception {
        if(id.startsWith("880") == false || id.length()!=8){
            throw new Exception("id 以 880开头的 8位数据");
        }
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    // age [18,30]
    public void setAge(int age) throws MyException {
        if (age<18 || age>30){
            throw new MyException("年龄在18到30岁之间！");
        }
        this.age = age;
    }
}
